package cn.skyquant.quant4j.api.strategy;

import cn.skyquant.quant4j.sdk.util.time.CalendarUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class StrategyTestDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    public int id;
    public String strategyName;
    public String name;
    public String version;
    public String userName;
    public Date startTime;
    public Date endTime;
    public Date beginDate;
    public Date endDate;
    public double initMoney;
    public double endMoney;
    public boolean isEnd;
    public List<StrategyParameter> parameterList = new ArrayList<>();

    public int getTestDays(){
        return CalendarUtils.getDiff(beginDate,endDate, Calendar.DATE);
    }
    public double getYields(){
        return new BigDecimal((endMoney-initMoney)/initMoney).setScale(4, RoundingMode.HALF_UP).doubleValue();
    }
    public double getYieldsPerDay(){
        return getTestDays()==0?0:new BigDecimal(getYields()/getTestDays()).setScale(5, RoundingMode.HALF_UP).doubleValue();
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof StrategyTestDTO)) return false;
        StrategyTestDTO that = (StrategyTestDTO) o;
        return id == that.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
